var regioni = document.getElementById("regionValue").value;
var provincei = document.getElementById("provinceValue").value;
var citiesi = document.getElementById("citiesValue").value;
var oneChanneli = document.getElementById("oneChannelValue").value;
var twoChanneli = document.getElementById("twoChannelValue").value;
var thrChanneli = document.getElementById("thrChannelValue").value;
var oneMediumi = document.getElementById("oneMediumValue").value;
var twoMediumi = document.getElementById("twoMediumValue").value;
var thrMediumi = document.getElementById("thrMediumValue").value;
var ChannelList;
var MediumList;
$.post(Feng.ctxPath + "/channel/getChannelsss", function (data) {//初始化下拉渠道列表
    ChannelList = data;
    channelInit('oneChannel', 'twoChannel', 'thrChannel');
    $("#oneChannel").attr("disabled", true).css('background', '#ebebe4');
    $("#twoChannel").attr("disabled", true).css('background', '#ebebe4');
    $("#thrChannel").attr("disabled", true).css('background', '#ebebe4');
}, "json");
$.post(Feng.ctxPath + "/medium/getMedium", function (data) {//初始化下拉媒介列表
    MediumList = data;
    mediumInit('oneMedium', 'twoMedium', 'thrMedium');
    if (oneChanneli != "直接上门") {
        $("#oneMedium").attr("disabled", true).css('background', '#ebebe4');
        $("#twoMedium").attr("disabled", true).css('background', '#ebebe4');
        $("#thrMedium").attr("disabled", true).css('background', '#ebebe4');
    }
    var oneMediumValue = $('#oneMediumValue').val();
    if (oneMediumValue != "") {
        $("#oneMedium option[value='" + oneMediumValue + "']").attr("selected", "selected");
    }
    var twoMediumValue = $('#twoMediumValue').val();
    if (twoMediumValue != "") {
        $("#twoMedium option[value='" + twoMediumValue + "']").attr("selected", "selected");
    }
    var thrMediumValue = $('#thrMediumValue').val();
    if (thrMediumValue != "") {
        $("#thrMedium option[value='" + thrMediumValue + "']").attr("selected", "selected");
    }
}, "json");
addressInit('province', 'cities', 'region');
var seletepayservicename = $('#payservicenameValue').val();
if (seletepayservicename != "") {//选中，市场录入的预约项目
    $("#treatmentUnit option[value='" + seletepayservicename + "']").attr("selected", "selected");
    $("#treatmentUnit").attr("disabled", "disabled").css("background", "#eeeeee")
}
var seleteconsumptionHabits = $('#consumptionHabitsValue').val();
if (seleteconsumptionHabits != "") {
    $("#consumptionHabits option[value='" + seleteconsumptionHabits + "']").attr("selected", "selected");
}
var seletecharacters = $('#charactersValue').val();
if (seletecharacters != "") {
    $("#characters option[value='" + seletecharacters + "']").attr("selected", "selected");
}
var seleteoccupation = $('#occupationValue').val();
if (seleteoccupation != "") {
    $("#occupation option[value='" + seleteoccupation + "']").attr("selected", "selected");
}
var seleteconsumAbility = $('#consumAbilityValue').val();
if (seleteconsumAbility != "") {
    $("#consumAbility option[value='" + seleteconsumAbility + "']").attr("selected", "selected");
}
var seletephoneSharShip = $('#phoneSharShipValue').val();
if (seletephoneSharShip != "") {
    $("#phoneSharShip option[value='" + seletephoneSharShip + "']").attr("selected", "selected");
}
var seletecustomerSex = $('#customerSexValue').val();
if (seletecustomerSex != "") {
    $("#customerSex option[value='" + seletecustomerSex + "']").attr("selected", "selected");
}
var seletemaritalStatus = $('#maritalStatusValue').val();
if (seletemaritalStatus != "") {
    $("#maritalStatus option[value='" + seletemaritalStatus + "']").attr("selected", "selected");
}
var seleteisHaveChildren = $('#isHaveChildrenValue').val();
if (seleteisHaveChildren != "") {
    $("#isHaveChildren option[value='" + seleteisHaveChildren + "']").attr("selected", "selected");
}

$("#birthday").on("input", function () {
    var resbirthday = /^(19\d\d|20\d\d)[-/ ](0\d|1[0-2])[-/ ](0\d|[1-2]\d|30|31)$/;
    var birthday = $("#birthday").val();
    if (birthday.length > 0 && birthday.length < 4) {
    } else if (birthday.length >= 4 && birthday.length < 10) {
        var s = birthday.substring(0, 4);
        if (!isNaN(s)) {
            var data = new Date();
            $("#customerAge").val(data.getFullYear() - s)
        }
    } else {
        if (resbirthday.test(birthday)) {
            var birthDayTime = new Date(birthday).getTime();
            var nowTime = new Date().getTime();
            $("#customerAge").val(Math.ceil((nowTime - birthDayTime) / 31536000000))
        } else {
            Feng.error("请输入正确的格式！")
        }
    }
});

$("#customerAge").on('input', function () {//输入年龄出生日期显示
    var date = new Date();
    var currentYear = date.getFullYear() - $("#customerAge").val();
    $("#birthday").val(currentYear + "-01-01")
});

$(function () {
    var date = new Date();
    var currentYear = date.getFullYear() - $("#customerAge").val();
    $("#birthday").val(currentYear + "-01-01")
});